#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

const int maxn = 1e5 + 500;
int a[maxn], n;
int b[maxn];
int best = INT_MIN;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> a[i];
    b[1] = a[1];
    for (int i = 2; i <= n; i++) {
        b[i] = b[i - 1] + a[i];
    }

    //copy(b,b+n,ostream_iterator<int>(cout," "));
    for (int left = 1; left <= n; ++left) {
        for (int right = left; right <= n; ++right) {
            //sum
            int sum = b[right] - b[left - 1];

            if (sum > best)best = sum;
        }
    }
    cout<<best;
    return 0;
}
